<template>
  <div class="restaurants">
    <div>附近商家</div>
    <ul>
      <li v-for="(item,index) in shoplist" :key="index" @click="godetail(item)">
        <div class="pic">
          <img :src="src+item.image_path" alt />
        </div>
        <div class="detail">
          <div>{{item.name}}</div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import http from "../../network/request";
import bus from "../../components/bus";
export default {
  beforeDestroy() {
    bus.$emit("getshopmsg", this.detail);
  },
  methods: {
    godetail(item) {
      //
      this.detail = item;
      console.log("跳转前");
      this.$router.push(`/shopdetail?id=${item.id}`);
    },
  },
  data() {
    return {
      shoplist: [],
      detail: {},
      src: "https://elm.cangdu.org/img/",
    };
  },
  created() {
    // console.log(this.$store.state.geohash);
    // let hash = this.$store.state.geohash.split(",");
    http({
      //url: `/shopping/restaurants?latitude=${hash[0]}&longitude=${hash[1]}`,
      url: `/shopping/restaurants?latitude=1&longitude=1`,
    })
      .then((res) => {
        this.shoplist = res.data;
        console.log(this.shoplist);
        console.log("http");
      })
      .then(() => {
        console.log("next");
        console.log(this.shoplist);
      });
  },
  mounted() {
    this.$nextTick(() => {});
  },
};
</script>

<style>
.restaurants ul li {
  display: flex;
  width: 100%;
  box-shadow: 1px 1px 0.6px #666;
}
.restaurants ul li {
  flex: 1;
}
.restaurants ul li .pic {
  width: 25%;
}
.restaurants ul li .pic img {
  width: 2.5rem;
}
.restaurants ul li .detail {
  flex: 1;
}
</style>